<?php

namespace slinks\extensions\action\configuration;

use slinks\extensions\action\interceptor\InterceptorStack;
use slinks\core\DependencyInjection\ContainerBuilder;
use slinks\core\dependencyInjectionExt\ContainerUtil;

/**
 * Builds a configuration based upon SlinksAction setup. 
 * @author Navid Mitchell
 *
 */
class ConfigurationBuilder {
    /* @var $container ContainerBuilder */

    private $container;

    function __construct(ContainerBuilder $container) {
        $this->container = $container;
    }

    /**
     * Add an IActionMapping to the configuration.
     *
     * @param IActionMapping $actionMapping
     */
    public function addActionMapping(IActionMapping $actionMapping) {
        ContainerUtil::setValueForArrayParameter($this->container, ConfigurationConstants::actionMappingsParameter(), $actionMapping->getName(), $actionMapping);
    }

    /**
     * Add a IResult to the configuration.
     *
     * @param IResult $result
     */
    public function addResultConfig(IResultConfig $result) {
        ContainerUtil::setValueForArrayParameter($this->container, ConfigurationConstants::resultConfigsParameter(), $result->getName(), $result);
    }

    /**
     * Add an InterceptorStack to the configuration.
     *
     * @param InterceptorStack $stack
     */
    public function addInterceptorStack(InterceptorStack $stack) {
        ContainerUtil::setValueForArrayParameter($this->container, ConfigurationConstants::interceptorStacksParameter(), $stack->getName(), $stack);
    }

    /**
     *
     * @param $defaultInterceptorStackName
     */
    public function setDefaultInterceptorStackName($defaultInterceptorStackName) {
        $this->container->setParameter(ConfigurationConstants::defaultInterceptorStackParameter(), $defaultInterceptorStackName);
    }

    /**
     *
     * @param $defaultResultName
     */
    public function setDefaultResultName($defaultResultName) {
        $this->container->setParameter(ConfigurationConstants::defaultResultParameter(), $defaultResultName);
    }

}